
package guoan.web.webCustomer;

import guoan.core.dto.DataGridModel;
import guoan.core.dto.PageResponse;
import guoan.core.dto.RestResponse;
import guoan.domain.Adv;
import guoan.domain.AdvType;
import guoan.service.AdvTypeService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.base.Preconditions;

@Controller
@RequestMapping("/webCustomer/advType")
public class AdvTypeController {
    protected final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    private AdvTypeService advTypeService;

    /**
     * 跳转到不同的内容页面
     * 
     * @param type
     * @return
     */
    @RequestMapping(value = "index", method = RequestMethod.GET)
    public String index(){
        return "/webCustomer/advType/index";
    }

    @RequestMapping(value = "data", method = RequestMethod.POST)
    @ResponseBody
    public PageResponse<AdvType> data(DataGridModel dataGridModel){
        return advTypeService.page(dataGridModel);
    }

    /** 查看 */
    @RequestMapping(value = { "update", "add" }, method = RequestMethod.GET)
    public String toUpdate(Long id, Model model){
        if (id != null) {
            AdvType advType = advTypeService.findOne(id);
            model.addAttribute("advType", advType);
        }
        return "/webCustomer/advType/add";
    }

    /** 保存 */
    @RequestMapping(value = "save", method = RequestMethod.POST)
    @ResponseBody
    public RestResponse<Boolean> save(AdvType advType, Model model){
        Preconditions.checkNotNull(advType, "参数错误");
        advTypeService.save(advType);
        return RestResponse.ok(true);
    }

    @RequestMapping(value = "del", method = RequestMethod.GET)
    @ResponseBody
    public RestResponse<Boolean> del(Long id){
        Preconditions.checkNotNull(id, "参数错误");
        advTypeService.del(id);
        return RestResponse.ok(true);
    }
}
